﻿using System;
using System.Collections.Generic;
using System.Linq;

using TempEmployees.DAL;
using TempEmployees.BLL.Database;

namespace TempEmployees.BLL.EntitiesExtensions
{
    public static class EAnamReport
    {
        public static AnamReport CreateAnamReport(string id, DateTime date, decimal hours, string budget, decimal salary)
        {
            AnamReport report = new AnamReport();

            report.RelevantDate = date;
            report.WorkingHours = hours;
            report.BudgetNumber = budget;
            report.Salary = salary;

            //Assumes that employee works in one department per semester... If needed, can also compare the budget number
            int semesterId = ESemester.GetRelevantSemesterId(date);
            Filters filters = new Filters();
            filters.Add("EmployeeID", id);
            filters.Add("SemesterID", semesterId);
            List<Assignment> assignments = DbQuery.GetTableRows<Assignment>(filters);

            if (assignments.Count != 1) return null;//need to throw exception of some kind...
            report.AssignmentID = assignments[0].ID;

            return report;
        }

        public static void SubmitReport(AnamReport report)
        {
            DbQuery.Insert<AnamReport>(report);
        }

        public static void SubmitReports(List<AnamReport> reports)
        {
            DbQuery.InsertAll<AnamReport>(reports);
        }
    }
}